#include <iostream>
#include <string>
using namespace std;

typedef long long LL;


string a; LL b;
LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a % b);
}

LL calc()
{
    LL r = 0;
    for (auto ch : a)    
        r = (r * 10 + ch - '0') % b;
    return r;
}
int main()
{
    cin >> a >> b;

    cout << gcd(b,calc()) << endl;
 
    return 0;
}








